package com.book.demo.demo.controller;

import com.book.demo.demo.model.BookInfo;
import com.book.demo.demo.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("/book")
public class BookController {
    /**
     * 书籍表现层*/

    // 引入业务逻辑层对象
    @Autowired
    private BookService bookService;

    /**
     * 获取图书列表
     * 测试：初步测试通过，没有问题*/
    @CrossOrigin(origins = "http://localhost:5173")
    @RequestMapping("/getlist")
    public List<BookInfo> getBookList() {
        // 由于没有token进行校验，因此直接返回图书数据
        // 调用数据逻辑层方法获取数据
        List<BookInfo> bookInfoList = bookService.getBookList();
        return bookInfoList.subList(0, 10);
    }
}
